package refactortips.editors.designPatterns;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;

import refactortips.editors.AbstractRefactorTipsEditor;

public class ObserverEditor extends AbstractRefactorTipsEditor {

	protected final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	
	public ObserverEditor() {
	}

	/**
	 * Create contents of the editor part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		
		Form frmDesignPattern = formToolkit.createForm(parent);
		formToolkit.paintBordersFor(frmDesignPattern);
		frmDesignPattern.setText("Observer");
		frmDesignPattern.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
		
		TabFolder tabFolder = new TabFolder(frmDesignPattern.getBody(), SWT.NONE);
		formToolkit.adapt(tabFolder);
		formToolkit.paintBordersFor(tabFolder);
		
		ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		sc.setExpandHorizontal(true);
	    sc.setExpandVertical(true);
		
		TabItem tbtmDescription = new TabItem(tabFolder, SWT.NONE);
		tbtmDescription.setText("Descri\u00E7\u00E3o");
		
		ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmDescription.setControl(scrolledComposite);
		formToolkit.paintBordersFor(scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		Composite composite_3 = new Composite(scrolledComposite, SWT.NONE);
		formToolkit.adapt(composite_3);
		formToolkit.paintBordersFor(composite_3);
		composite_3.setLayout(null);
		
		Label label = new Label(composite_3, SWT.NONE);
		label.setImage(ResourceManager.getPluginImage("RefactorTips", "images/designPatterns/observer.png"));
		label.setBounds(195, 27, 518, 261);
		formToolkit.adapt(label, true, true);
		
		Label label_1 = new Label(composite_3, SWT.NONE);
		label_1.setText("Prop\u00F3sito");
		label_1.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		label_1.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		label_1.setBounds(10, 314, 102, 25);
		formToolkit.adapt(label_1, true, true);
		
		StyledText styledText = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText.setText("Permite que um ou mais objetos sejam notificados sobre mudan\u00E7as de estado em outros objetos dentro do sistema.");
		styledText.setJustify(true);
		styledText.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText.setEnabled(false);
		styledText.setDoubleClickEnabled(false);
		styledText.setBounds(25, 361, 830, 52);
		formToolkit.adapt(styledText);
		formToolkit.paintBordersFor(styledText);
		
		Label label_2 = new Label(composite_3, SWT.NONE);
		label_2.setText("Usar quando:");
		label_2.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		label_2.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		label_2.setBounds(10, 436, 120, 25);
		formToolkit.adapt(label_2, true, true);
		
		StyledText styledText_1 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_1.setText("- Mudan\u00E7as de estado em um ou mais objetos devem disparar comportamento em outros objetos.\r\n- Capacidade de divulga\u00E7\u00E3o \u00E9 requerida.\r\n- Percebe-se que objetos ficar\u00E3o cegos (n\u00E3o ser\u00E3o notificados) devido ao custo de inserir uma notifica\u00E7\u00E3o.");
		styledText_1.setJustify(true);
		styledText_1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_1.setEnabled(false);
		styledText_1.setDoubleClickEnabled(false);
		styledText_1.setBounds(25, 483, 830, 108);
		formToolkit.adapt(styledText_1);
		formToolkit.paintBordersFor(styledText_1);
		scrolledComposite.setContent(composite_3);
		scrolledComposite.setMinSize(composite_3.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmUsage = new TabItem(tabFolder, SWT.NONE);
		tbtmUsage.setText("Exemplo");
		
		ScrolledComposite scrolledComposite_1 = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmUsage.setControl(scrolledComposite_1);
		formToolkit.paintBordersFor(scrolledComposite_1);
		scrolledComposite_1.setExpandHorizontal(true);
		scrolledComposite_1.setExpandVertical(true);
		
		Composite composite = new Composite(scrolledComposite_1, SWT.NONE);
		formToolkit.adapt(composite);
		formToolkit.paintBordersFor(composite);
		
		Label label_3 = new Label(composite, SWT.NONE);
		label_3.setText("Exemplo");
		label_3.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		label_3.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		label_3.setBounds(10, 10, 77, 25);
		formToolkit.adapt(label_3, true, true);
		
		StyledText styledText_2 = new StyledText(composite, SWT.READ_ONLY | SWT.WRAP);
		styledText_2.setText("\t\tEsse padr\u00E3o pode ser encontrado em quase todos as interfaces com o usu\u00E1rio (GUI). Quando bot\u00F5es, texto, e outros campos s\u00E3o colocados em aplica\u00E7\u00F5es, a aplica\u00E7\u00E3o tipicamente registra como um listener (ouvinte) para esses controles. Quando um usu\u00E1rio dispara um evento, como ao clicar um bot\u00E3o, o controle itera pelos seus observadores registrados e envia uma notifica\u00E7\u00E3o para cada um.");
		styledText_2.setJustify(true);
		styledText_2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_2.setEnabled(false);
		styledText_2.setDoubleClickEnabled(false);
		styledText_2.setBounds(25, 57, 831, 108);
		formToolkit.adapt(styledText_2);
		formToolkit.paintBordersFor(styledText_2);
		
		Label label_4 = new Label(composite, SWT.NONE);
		label_4.setImage(ResourceManager.getPluginImage("RefactorTips", "images/designPatterns/observer/observerSample1.png"));
		label_4.setBounds(179, 217, 544, 327);
		formToolkit.adapt(label_4, true, true);
		
		Label lblExemplo = new Label(composite, SWT.NONE);
		lblExemplo.setText("Exemplo 2");
		lblExemplo.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblExemplo.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		lblExemplo.setBounds(10, 185, 93, 25);
		formToolkit.adapt(lblExemplo, true, true);
		scrolledComposite_1.setContent(composite);
		scrolledComposite_1.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmVideo = new TabItem(tabFolder, SWT.NONE);
		tbtmVideo.setText("Video");
		
		Browser browser = new Browser(tabFolder, SWT.NONE);
		browser.setUrl("www.youtube.com/embed/mXa3P2274mU");
		tbtmVideo.setControl(browser);
		formToolkit.paintBordersFor(browser);
	}
}
